package com.hualan.sfzy.utils;


import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;

import java.io.InputStream;

public class OSSUtil {
    private static final String endpoint = "https://oss-cn-hangzhou.aliyuncs.com";
    private static final String accessKeyId = "LTAI5t6zNxUH7JNTrssUhnh4";
    private static final String accessKeySecret = "ATwSzX9Cty0UO3rTzK5ObTWgK1B3ht";
    private static final String bucketName = "gyqsfzy";
    private static String objectName = "upload/";
    public static String upload(String fileName, InputStream inputStream) {
        objectName += fileName;
        OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
        ossClient.putObject(bucketName, objectName, inputStream);
        String url = "https://gyqsfzy.oss-cn-hangzhou.aliyuncs.com/" + objectName;
        objectName = "upload/";
        ossClient.shutdown();
        return url;
    }
}
